/////////////////////////////////////////////二次弹窗动作//////////////////////////////////////////////////
var playerLandActionId;
var playerLandActionName;
//显示用户交互页面信息
function doPlayerFarmAction(type,landId) {
	if(playerLandId != landId){
		showPersonalMessage(_game_name_, "您的操作错误，请刷新页面重试");
		return;
	}
	//alert(playerLandId);
	let srcUrl = '/game/1.0/sfg/action';
	if (type == 1) {//关闭
		closePlayerOperateDiv();
		return;
	} else if (type == 10) {//翻地
		playerLandActionName = "翻地";
		srcUrl = srcUrl + '/turn.js';
	} else if (type == 20) {//播种
		//切换到种子页面
		//playerPropId = '110163877495551300010000'; 测试数据
		if (checkEmpty(playerPropId)) {
			showPlayerInteractDiv('20');
		}else{
			playerLandActionName = "播种";
			srcUrl = srcUrl + '/sow.js';
		}
	} else if (type == 30) {//收割
		playerLandActionName = "收割";
		srcUrl = srcUrl + '/harvest.js';
	} else if (type == 40) {//开垦
		playerLandActionName = "开垦";
		srcUrl = srcUrl + '/bring.js';
	} else if (type == 50) {//浇水
		playerLandActionName = "浇水";
		srcUrl = srcUrl + '/watering.js';
	} else if (type == 60) {//施肥
		playerLandActionName = "施肥";
		srcUrl = srcUrl + '/fertilize.js';
	} else if (type == 70) {//除草
		playerLandActionName = "除草";
		srcUrl = srcUrl + '/weed.js';
	} else if (type == 80) {//杀虫
		playerLandActionName = "杀虫";
		srcUrl = srcUrl + '/insecticidal.js';
	} else {//关闭
		closePlayerOperateDiv();
		return;
	}
	playerLandActionId = landId;
	//数据交互
	playerInteractiveServerAction10(srcUrl);
	//关闭
	closePlayerOperateDiv();
}

//清空缓冲区
function clearData(){
	playerLandId = '';
	playerPropId = ''; 
 	playerFriendId = ''; 
	playerLandActionId = ''; 
 	playerLandActionName = ''; 
}

//服务器交互请求
function playerInteractiveServerAction10(srcUrl) {
	if (checkEmpty(playerLandId)) {
		showPersonalMessage(_game_name_, "请选择一块土地再进行操作");
		return;
	}
	$.ajax({
		type: "POST",
		url: ajaxUrl + srcUrl + "?jobId=" + getTimeMs(),
		data: {
			token: window.localStorage.getItem('token'),
			sid: currentSID,
			gameId: 'SFG',
			playerLandId: playerLandId,
			playerPropId: playerPropId,
		},
		dataType: "JSON",
		success: function(request) {
			console.log(request);
			//刷新土地状态
			if (request.code != 0) {
				doErrorMessage(request.code, request.msg);
			} else {
				let land = request.data;//土地数据
				current_player_farm_lands_detail.put('land_'+playerLandIndex, land);
				changePlayerFarmLandDetail(land,playerLandActionId);
				//提示信息
				showPersonalMessage(_game_name_, playerLandActionName + "操作成功");
				//更新操作结果
				gamePlayerFarmInfo(1);//更新用户数据
			}
			//关闭
			closePlayerOperateDiv();
			//清空缓冲区
			clearData();
		},
		error: function(error) {
			console.log(error);
		}
	});
}

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//功能区交互//////////////////////////////////////////
//显示用户交互页面信息
function doPlayerInteractAction(type,landId) {
	playerPropId = landId;
	//alert(playerPropId);
	//alert(playerLandId);
	let srcUrl = '/game/1.0/sfg/player';
	if (type == 1) {//关闭
		closePlayerCommonOperateDiv();
	} else if (type == 11) {//出售
		srcUrl = srcUrl + '/warehouse-sell.js';
	} else if (type == 21) {//使用
		//种子种植
		//srcUrl = srcUrl + '/pocket-use.js';
		doPlayerFarmAction(20,playerLandId);
		//关闭展示窗口
		closePlayerInteractDiv(999);
		//关闭二次功能窗口
		closePlayerCommonOperateDiv();
		return;
	} else if (type == 22) {//销毁
		srcUrl = srcUrl + '/pocket-drop.js';
	} else if (type == 31) {//购买
		srcUrl = srcUrl + '/store-buy.js';
	} else if (type == 41) {//查看
		srcUrl = srcUrl + '/friend.js';
	} else {//关闭
		closePlayerCommonOperateDiv();
	}
	//数据交互
	playerInteractiveServerAction00(srcUrl);
}

//服务器交互请求
function playerInteractiveServerAction00(srcUrl) {
	if (checkEmpty(playerPropId)) {
		showPersonalMessage(_game_name_, "请选择一块土地再进行操作");
		return;
	}
	$.ajax({
		type: "POST",
		url: ajaxUrl + srcUrl + "?jobId=" + getTimeMs(),
		data: {
			token: window.localStorage.getItem('token'),
			sid: currentSID,
			gameId: 'SFG',
			playerLandId: playerLandId,
			playerPropId: playerPropId,
		},
		dataType: "JSON",
		success: function(request) {
			console.log(request);
			//刷新土地状态
			if (request.code != 0) {
				doErrorMessage(request.code, request.msg);
			} else {
				current_player_farm = request.data;
			}
			//清空缓冲区
			clearData();
		},
		error: function(error) {
			console.log(error);
		}
	});
}

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//功能区交互//////////////////////////////////////////
//添加好友
var playerFriendId;
function doPlayerFriendAction(type,id) {
	let srcUrl = '/game/1.0/sfg/interact';
	if (type == 1) {//关闭
		closePlayerFriendDiv();
	} else if (type == 10) {//添加好友
		srcUrl = srcUrl + '/friend.js';
	} else {//关闭
		closePlayerFriendDiv();
		return;
	}
	playerFriendId = id;
	//数据交互
	playerInteractiveServerAction20(srcUrl);
}

//服务器交互请求
function playerInteractiveServerAction20(srcUrl) {
	if (checkEmpty(playerFriendId)) {
		showPersonalMessage(_game_name_, "请选择一个目标后再次操作");
		return;
	}
	$.ajax({
		type: "POST",
		url: ajaxUrl + srcUrl + "?jobId=" + getTimeMs(),
		data: {
			token: window.localStorage.getItem('token'),
			sid: currentSID,
			gameId: 'SFG',
			playerFriendId: playerFriendId,
		},
		dataType: "JSON",
		success: function(request) {
			console.log(request);
			//刷新状态
			if (request.code != 0) {
				doErrorMessage(request.code, request.msg);
			} else {
				doSystemMessage(request.msg);
			}
			//关闭
			closePlayerFriendDiv();
			//清空缓冲区
			clearData();
		},
		error: function(error) {
			console.log(error);
		}
	});
}